let fn = async (fingerprint, ctx, topic) => {
    // 需要原地修改 ctx.user，所以不能在参数里解构
    let { socket, reg, WARNING, USER_INFO } = ctx
    try {
        if (!fingerprint) {
            fingerprint = Math.random().toString(36).substring(2, 12)
            socket.emit(topic, fingerprint)
        }
        // inplace
        ctx.user = await reg.users.conn(fingerprint, socket)
        socket.emit(USER_INFO, ctx.user.toSender())
    } catch (e) {
        socket.emit(WARNING, {
            topic,
            data: e.message
        })
    }
}

module.exports = fn